
/**
 *  \file hci_extern.h
 *
 *  This file contains external declarations of all the global variables
 *  used in HCI Layer implementation.
 */

/*
 *  Copyright (C) 2013. Mindtree Ltd.
 *  All rights reserved.
 */

#ifndef _H_HCI_EXTERN_
#define _H_HCI_EXTERN_

/** To protect internal Data Structures in a multi-threaded environment */
BT_DEFINE_MUTEX_TYPE (extern, hci_mutex)

/** To store the Local BD_ADDR */
extern UCHAR hci_local_bd_addr [BT_BD_ADDR_SIZE];

/** Max Number of Commands that can be sent to the HC */
extern UCHAR hci_num_hci_command_packets;

#ifdef HCI_SCO
/** Host Controller SCO Data Buffer information */
extern UINT16 hci_max_no_sco_tx_packets;
extern UINT16 hci_max_sco_tx_pkt_size;
#endif /* HCI_SCO */

#ifdef HCI_ISO_DATA
/** Host Controller ISO Data Buffer information */
extern UINT16 hci_max_iso_tx_pkt_size;
extern UINT8 hci_max_no_iso_tx_packets;

/** HCI ISO Data Indication Callback */
extern API_RESULT(*hci_iso_data_ind_cb) (UCHAR *, UINT16);

/** Number of ISO Packets that can be transmitted to HCI */
extern UINT16 hci_no_iso_tx_packets;
#endif /* HCI_ISO_DATA */

/** HCI Host Controller to Host Flow Control Setting */
extern UCHAR hci_flow_control;

/** Local Bluetooth Device Name */
extern CHAR * hci_local_name;

#ifdef BT_HCI_1_2
/*
 *  To store eSCO Channel Parameters to be used while responding to
 *  eSCO Connection Request from Host Controller with Synchronous
 *  Connection Accept Command
 */
extern HCI_SCO_IN_PARAMS hci_esco_params;

#ifdef HCI_ENH_SCO
/* To Store Enhanced SCO Configuration Parameters */
extern HCI_ENH_SCO_PARAMS hci_enh_sco_params;
#endif /* HCI_ENH_SCO */
#endif /* BT_HCI_1_2 */

/**
 *  The list of known Remote Devices added explicitly during
 *  incoming/outgoing ACL connection requests.
 */
extern REMOTE_DEVICE hci_remote_devices [ BT_MAX_REMOTE_DEVICES ];

/** Device Attributes Table */
extern HCI_DEVICE_ATTR dev_attr_list [ HCI_MAX_DEVICE_ATTRIBUTES ];

/** Default HCI Role */
extern UCHAR hci_device_role;

/** HCI Buffer for Command Packets and related state */
extern HCI_COMMAND_Q_ELEMENT hci_command_queue [ HCI_COMMAND_QUEUE_SIZE ];
extern UINT16 hci_command_queue_start;
extern UINT16 hci_command_queue_end;

/** Flag - Is a HCI Command Enqueued ? */
extern UCHAR hci_schedule_command_tx;

#ifdef HCI_ISO_DATA
/** HCI Buffer for ISO Data Packets and related state */
extern HCI_ISO_DATA_Q_ELEMENT hci_iso_data_queue[HCI_ISO_DATA_QUEUE_SIZE];
extern UINT16 hci_iso_data_queue_start;
extern UINT16 hci_iso_data_queue_end;

/** Flag - Is a HCI ISO Data handler BH Enqueued ? */
extern UCHAR hci_schedule_iso_data_tx;
#endif /* HCI_ISO_DATA */

#ifdef HCI_HAVE_INIT_COMMAND_MASK
/**
 *  Mask (Bitmap) for HCI Commands that are allowed to be switched off
 *  (not to be sent) during HCI's Bluetooth-ON processing (HCI BT-Init).
 *
 *  Description of the Bitmap:
 *    Bit  0: 0 - Send HCI Reset Command (default)
 *            1 - Do NOT send HCI Reset Command
 *
 *  Bit 1-31: Reserved for future
 */
extern UINT32 hci_init_command_mask;
#endif /* HCI_HAVE_INIT_COMMAND_MASK */

/**
 *  Flag to indicate whether Event Indication Callback to be called or not.
 *  By default this will be switched on whenever HCI receives an Event. The
 *  Event Handler function decides if the callback needs to be called.
 */
extern UCHAR hci_call_event_ind_callback;

/**
 *  Flag to inidicate that HCI Init is Complete and to call the BT-ON
 *  complete callback.
 */
extern UCHAR hci_bt_init_complete_call_cb;

/** HCI Event Indication Callback */
extern API_RESULT (* hci_event_ind_cb )
                  (
                      UCHAR event_type,
                      UCHAR * event_data,
                      UCHAR event_datalen
                  ) DECL_REENTRANT;

#ifndef HCI_LITE
/** HCI Error Indication Callback */
extern API_RESULT (* hci_error_ind_cb) (UINT16 opcode, UINT16 error_code);
#endif  /* HCI_LITE */

#ifdef HCI_SCO
/** HCI SCO Data Indication Callback */
extern API_RESULT (* hci_sco_data_ind_cb) (UCHAR *, UINT16);
#endif /* HCI_SCO */

#ifdef BT_4_0
/** Random Address written to the controller */
extern UCHAR hci_random_address[BT_BD_ADDR_SIZE];

/** Random Address being configured for the controller */
extern UCHAR hci_config_random_address[BT_BD_ADDR_SIZE];

/* Address type used in the Advertisements */
extern UCHAR hci_adv_addr_type;

/** Address type being fonfiged for Adverisements */
extern UCHAR hci_config_adv_addr_type;

/** HCI encrypt command counter */
extern UCHAR hci_encrypt_cmd_counter;

/** HCI encrypt command complete counter */
extern UCHAR hci_encrypt_cmd_cmplt_counter;

#ifdef HOST_RESOLVE_PVT_ADDR
extern UINT16 hci_resolution_conn_handle;
#endif /* HOST_RESOLVE_PVT_ADDR */
#endif /* BT_4_0 */

#ifdef BT_SUPPORT_CONTROLLER_INIT_SKIP
extern UCHAR hci_skip_controller_bt_init;
#endif /* BT_SUPPORT_CONTROLLER_INIT_SKIP */

#ifdef HCI_CHECK_TARNSPORT_READINESS
/* Flag to indicate HCI transport is ready */
extern UCHAR hci_transport_ready;
#endif /* HCI_CHECK_TARNSPORT_READINESS */

#ifdef HCI_SUPPORT_LE_CONN_FAILURE_EVENT_WITH_NO_ADDR
/** HCI LE Connection Request Infomation */
extern HCI_LE_CONNECT_REQ_INFO hci_le_connect_req_info;
#endif /* HCI_SUPPORT_LE_CONN_FAILURE_EVENT_WITH_NO_ADDR */

#ifdef HCI_LE_EXT_ADV_SETS_LOCAL_ADDR_SUPPORT
/* HCI Extended ADV Parameters related Structure */
/**
 *  The list of Extended ADV Parameters related to
 *  different advertising sets.
 */
extern HCI_EXT_ADV_META_PARAM hci_le_ext_adv_param[HCI_MAX_SUPPORTED_EXT_ADV_SETS];

/**
 * This holds the current ADV handle index requested to being Set.
 */
extern UCHAR hci_le_curr_adv_hndl_id_2_set;

/**
 * This holds the current ADV handle requested to be removed.
 */
extern UCHAR hci_le_curr_adv_hndl_2_rem;
#endif /* HCI_LE_EXT_ADV_SETS_LOCAL_ADDR_SUPPORT */

#ifdef HCI_LE_CIG_CIS_SUPPORT
/**
 *  The list of CIS connections added explicitly during
 *  incoming/outgoing CIS connection requests.
 */
extern HCI_LE_CIS_CE hci_le_cis_list[HCI_MAX_CIS_CONNECTIONS];
#endif /* HCI_LE_CIG_CIS_SUPPORT */

#endif /* _H_HCI_EXTERN_ */

